package com.woniuxy.company5.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.company5.dto.FinMacDto;
import com.woniuxy.company5.entity.FinMac;
import com.woniuxy.company5.entity.FinMouthBill;
import com.woniuxy.company5.service.FinMacService;
import com.woniuxy.company5.util.Result;
import com.woniuxy.company5.vo.FinMacVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能描述
 *
 * @author PC
 * @date -2022/12/8-时间-20:18
 * @product company5
 */
@RestController
@RequestMapping("/FinMacs")
public class FinMacController {
    @Resource
    private FinMacService finMacService;
    @PostMapping("selAll")

    public Result selAll(@RequestBody FinMacDto finMacDto){
        PageHelper.startPage(finMacDto.getCurrentPage(),finMacDto.getPageSize(),true);
        PageHelper.orderBy("id desc");
        List<FinMacVo> finMacVos = finMacService.selAll(finMacDto);
        PageInfo<FinMacVo> pageInfo = new PageInfo<>(finMacVos);
        return Result.ok().data("macList",finMacVos).data("total",pageInfo.getTotal());

    }

    @PostMapping("")
    public Result add(@RequestBody FinMac finMac){
        int i = finMacService.insertSelective(finMac);
        if(i > 0){
            return Result.ok();
        }else{
            return Result.error();
        }

    }
    @GetMapping("{id}")
    public Result selOne(@PathVariable Long id){
        FinMac finMac = finMacService.selectByPrimaryKey(id);
        if(finMac != null){
            return Result.ok().data("list",finMac);
        }else {
            return Result.error();
        }
    }
    @PutMapping("")
    public Result update(@RequestBody FinMac finMac){
        int i = finMacService.updateByPrimaryKeySelective(finMac);
        if(i > 0){
            return Result.ok();
        }else{
            return Result.error();
        }
    }
    @DeleteMapping("{id}")
    public Result del(@PathVariable Long id){
        int i = finMacService.deleteByPrimaryKey(id);
        if(i > 0){
            return Result.ok();
        }else{
            return Result.error();
        }
    }
}
